package com.example.demo.arithmetic.algorithm.sort2024;

import java.util.Arrays;

public class ShellSort {
    public static void shellSort(int[] arr) {
        for (int gap = arr.length >> 1; gap >= 1; gap /= 2) {
            for (int low = gap; low < arr.length; low++) {
                int t = arr[low];
                int i = low - gap;
                while (i >= 0 && t < arr[i]) {
                    arr[i + gap] = arr[i];
                    i -= gap;
                }
                if (i != low - gap) {
                    arr[i + gap] = t;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {1, 3, 44, 52, 45, 445, 3333, 6, 5, 3, 5};
        shellSort(ints);
        System.out.println(Arrays.toString(ints));
    }
}
